#pragma once

#include <vhal_core/persist/PlatformProfile.h>

#include <unordered_set>
#include <unordered_map>
#include <vector>

using namespace ecarx::vhal::core::persist;

namespace ecarx::platform::profile {

class PlatformProfileImpl final : public PlatformProfile {
  public:
    PlatformProfileImpl();

    void onInit() override;
    Profile* getCurrentProfile() override;
    void addProfileListener(ProfileListener* listener) override;
    void removeProfileListener(ProfileListener* listener) override;
    std::shared_ptr<ProfileAuxiliary> getAuxiliary() override;
    std::vector<int32_t> getCreatedProfileIds() override;
    bool createProfile(int32_t newProfileId, int32_t cloneProfileId = 0) override;
    bool isCreated(int32_t profileId) override;
    bool deleteProfile(int32_t profileId) override;
    bool activeProfile(int32_t profileId) override;
    bool deleteCurrentProfilePreference(int32_t perferenceId) override;
    bool activeCurrentProfilePreference(int32_t perferenceId) override;

  private:
    std::string mPath;
    std::shared_ptr<ProfileAuxiliary> mAuxiliary = nullptr;
    std::unordered_map<int32_t, std::unique_ptr<Profile>> mProfiles;
    Profile* mActiveProfile = nullptr;
    std::unordered_set<ProfileListener*> mListeners;
    std::vector<int32_t> mCreatedProfileIds;

    void notifySwicthProfile(Profile* last, Profile* current);
};
}  // namespace ecarx::platform::profile
